package cn.kimming.generator;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.List;

import cn.kimming.wms.domain.BaseDomain;
import lombok.Getter;

/**
 * @author KimmingLau
 * 模板信息封装
 */
@Getter
public class ClassInfo {
	private String basePkg;	//基础包名
	private String className;	//类的简单名
	private String objectName;	//类的简单名(小写)
	private String entityName;	//实体类的中文名称
	private List<String> propNames = new ArrayList<>();	//类的属性名称
	
	public ClassInfo(Class<?> clz, String entityName) throws Exception {
		basePkg = clz.getPackage().getName().substring(0, clz.getPackage().getName().lastIndexOf("."));
		className = clz.getSimpleName();
		objectName = className.substring(0,1).toLowerCase() + className.substring(1);
		this.entityName = entityName;
		//内省机制
		BeanInfo beanInfo = Introspector.getBeanInfo(clz, BaseDomain.class);
		PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
		for (PropertyDescriptor pd : pds) {
			propNames.add(pd.getName());
		}
	}

	@Override
	public String toString() {
		return "ClassInfo [basePkg=" + basePkg + ", className=" + className + ", objectName=" + objectName
				+ ", entityName=" + entityName + ", propNames=" + propNames + "]";
	}
	
	
}
